package com.demo.controller;



import com.demo.annotation.GlobalInterceptor;
import com.demo.annotation.VerifyParam;
import com.demo.entity.enums.PermissionCodeEnum;
import com.demo.entity.po.DeviceInfo;

import com.demo.entity.query.DeviceInfoQuery;


import com.demo.entity.vo.ResponseVO;


import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import com.demo.service.DeviceInfoService;


@RestController
@RequestMapping("/device")
public class DeviceInfoController extends ABaseController {

	@Resource
	private DeviceInfoService deviceInfoService;


	/**
	 * 分页查询
	 */
	@RequestMapping("/loadDeviceList")
	@GlobalInterceptor(permissionCode = PermissionCodeEnum.DEVICE_LIST)
	public ResponseVO loadDeviceList(DeviceInfoQuery query) {
		query.setOrderBy("device_id desc");
		return getSuccessResponseVO(deviceInfoService.findListByPage(query));
	}



	@RequestMapping("/loadDeviceList4User")
	@GlobalInterceptor
	public ResponseVO loadDeviceList4User(DeviceInfoQuery query) {
		query.setOrderBy("device_id desc");
		query.setQueryOtherInfo(true);
		return getSuccessResponseVO(deviceInfoService.findListByPage(query));
	}


	/**
	 * 保存设备信息
	 */
	@RequestMapping("/saveDeviceInfo")
	@GlobalInterceptor(permissionCode = PermissionCodeEnum.DEVICE_EDIT)
	public ResponseVO saveDeviceInfo(DeviceInfo bean) {
		this.deviceInfoService.saveDeviceInfo(bean);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据DeviceId删除
	 */
	@RequestMapping("/delDeviceInfo")
	@GlobalInterceptor(permissionCode = PermissionCodeEnum.DEVICE_DEL)
	public ResponseVO delDeviceInfo(@VerifyParam(required = true) Integer deviceId) {
		this.deviceInfoService.deleteDeviceInfoByDeviceId(deviceId);
		return getSuccessResponseVO(null);
	}
}